package org.teach.study.springmvc.controller;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.teach.study.springmvc.vo.User;

/**
 * <b>HelloController。</b>
 * <p><b>详细说明：</b></p>
 * <!-- 在此添加详细说明 -->
 * 无。
 * 
 * @version 1.0
 * @author mex20
 * @since 1.0
 */
@Controller
public class HelloController {
	@RequestMapping({ "/", "/index.html" })
	public String hello() {
		return "index";
	}

	@RequestMapping(value = "/login", method = { RequestMethod.GET, RequestMethod.POST })
	public String login(@RequestParam String userName,@RequestParam String password, HttpSession session) {
		if ("admin".equals(userName)) {
			User user = new User(userName, password);
			session.setAttribute("user", user);
		}
		return "index";
	}

	@RequestMapping("/register")
	public String register(Model mode) {
		
		mode.addAttribute("success", "注册成功");
		return "register";
	}

	@RequestMapping("/test")
	public String test() {
		return "redirect:/user/loginUser";
	}
}
